package mvc_generator.generator.car.struts;

import mvc_generator.generator.MVCGeneratorGeneratorUtils;
import mvc_generator.generator.car.struts.StrutsGenerator;
import mvc_generator.mVCGenerator.Controller;
import mvc_generator.mVCGenerator.FormValidation;
import mvc_generator.mVCGenerator.ModelMVC;
import mvc_generator.mVCGenerator.View;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.xbase.lib.StringExtensions;

@SuppressWarnings("all")
public class StrutsConfigGenerator {
  public void generate(final ModelMVC model, final IFileSystemAccess fsa) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence strutsConfig = _builder;
    StringConcatenation _builder_1 = new StringConcatenation();
    CharSequence formBeans = _builder_1;
    StringConcatenation _builder_2 = new StringConcatenation();
    CharSequence actionMappings = _builder_2;
    int i = 0;
    int j = 0;
    int k = 0;
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append("<form-beans>");
    _builder_3.newLine();
    {
      EList<Controller> _controllers = model.getControllers();
      for(final Controller c : _controllers) {
        _builder_3.append("\t");
        int _j = j = 0;
        MVCGeneratorGeneratorUtils.toVoidExpr(Integer.valueOf(_j));
        _builder_3.newLineIfNotEmpty();
        {
          EList<FormValidation> _formValidations = c.getFormValidations();
          for(final FormValidation fv : _formValidations) {
            _builder_3.append("\t");
            _builder_3.append("<form-bean name=\"");
            View _controlledView = c.getControlledView();
            String _name = _controlledView.getName();
            String _firstUpper = StringExtensions.toFirstUpper(_name);
            _builder_3.append(_firstUpper, "	");
            _builder_3.append("ValidationForm\"");
            _builder_3.newLineIfNotEmpty();
            _builder_3.append("\t");
            _builder_3.append("\t");
            _builder_3.append("type=\"");
            _builder_3.append(StrutsGenerator.actionFormPath, "		");
            int _plus = (i + 1);
            int _i = i = _plus;
            _builder_3.append(_i, "		");
            _builder_3.append("\" />");
            _builder_3.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder_3.append("\t");
    _builder_3.append("</form-beans>");
    _builder_3.newLine();
    formBeans = _builder_3;
    StringConcatenation _builder_4 = new StringConcatenation();
    _builder_4.append("<action-mappings>");
    _builder_4.newLine();
    {
      EList<Controller> _controllers_1 = model.getControllers();
      for(final Controller c_1 : _controllers_1) {
        {
          EList<FormValidation> _formValidations_1 = c_1.getFormValidations();
          for(final FormValidation fv_1 : _formValidations_1) {
            _builder_4.append("<action path=\"/actionForm");
            View _controlledView_1 = c_1.getControlledView();
            String _name_1 = _controlledView_1.getName();
            String _firstUpper_1 = StringExtensions.toFirstUpper(_name_1);
            _builder_4.append(_firstUpper_1, "");
            String _validatedFormName = fv_1.getValidatedFormName();
            String _firstUpper_2 = StringExtensions.toFirstUpper(_validatedFormName);
            _builder_4.append(_firstUpper_2, "");
            _builder_4.append("\" type=\"");
            _builder_4.append(StrutsGenerator.servletActionPath, "");
            View _controlledView_2 = c_1.getControlledView();
            String _name_2 = _controlledView_2.getName();
            String _firstUpper_3 = StringExtensions.toFirstUpper(_name_2);
            _builder_4.append(_firstUpper_3, "");
            _builder_4.append("Action\"");
            _builder_4.newLineIfNotEmpty();
            _builder_4.append("name=\"");
            View _controlledView_3 = c_1.getControlledView();
            String _name_3 = _controlledView_3.getName();
            String _firstUpper_4 = StringExtensions.toFirstUpper(_name_3);
            _builder_4.append(_firstUpper_4, "");
            String _validatedFormName_1 = fv_1.getValidatedFormName();
            String _firstUpper_5 = StringExtensions.toFirstUpper(_validatedFormName_1);
            _builder_4.append(_firstUpper_5, "");
            _builder_4.append("ValidationForm\" scope=\"request\" input=\"/pages/");
            View _controlledView_4 = c_1.getControlledView();
            String _name_4 = _controlledView_4.getName();
            _builder_4.append(_name_4, "");
            _builder_4.append(".jsp\">");
            _builder_4.newLineIfNotEmpty();
            {
              EList<View> _viewsOnSuccess = fv_1.getViewsOnSuccess();
              for(final View view : _viewsOnSuccess) {
                _builder_4.append("<forward name=\"");
                String _name_5 = view.getName();
                _builder_4.append(_name_5, "");
                _builder_4.append("\" path=\"/pages/");
                String _name_6 = view.getName();
                _builder_4.append(_name_6, "");
                _builder_4.append(".jsp\" />");
                _builder_4.newLineIfNotEmpty();
              }
            }
          }
        }
        _builder_4.append("</action>\t\t\t");
        _builder_4.newLine();
      }
    }
    _builder_4.append("</action-mappings>");
    _builder_4.newLine();
    actionMappings = _builder_4;
    StringConcatenation _builder_5 = new StringConcatenation();
    _builder_5.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
    _builder_5.newLine();
    _builder_5.append("<!DOCTYPE struts-config PUBLIC");
    _builder_5.newLine();
    _builder_5.append("\"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN\"");
    _builder_5.newLine();
    _builder_5.append("\"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd\">");
    _builder_5.newLine();
    _builder_5.append("<struts-config>");
    _builder_5.newLine();
    _builder_5.append(formBeans, "");
    _builder_5.newLineIfNotEmpty();
    _builder_5.append(actionMappings, "");
    _builder_5.newLineIfNotEmpty();
    _builder_5.append("\t");
    _builder_5.append("<!-- ========== Ressources de definitions de messages =========================== -->");
    _builder_5.newLine();
    _builder_5.append("\t");
    _builder_5.append("<message-resources parameter=\"Resources\" />");
    _builder_5.newLine();
    _builder_5.append("</struts-config>\t\t");
    _builder_5.newLine();
    strutsConfig = _builder_5;
    String _name_7 = model.getName();
    String _plus_1 = (_name_7 + "Struts");
    String _plus_2 = (_plus_1 + StrutsGenerator.configPath);
    String _plus_3 = (_plus_2 + "struts-config.xml");
    fsa.generateFile(_plus_3, strutsConfig);
  }
}
